package com.bandi.tharshesnows.http;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpRequester {

  public InputStream postHttpGet(String urlStr) throws Throwable {
    int maxRetries = 2;
    int currentRetries = 0;
    HttpURLConnection urlConnection = null;
    Throwable e = new Throwable("Error");
    while (currentRetries != maxRetries) {
      try {
        currentRetries++;
        URL url = new URL(urlStr);
        urlConnection = (HttpURLConnection) url.openConnection();
        return urlConnection.getInputStream();
      }
      catch (Throwable t) {
        e = t;
      }
      finally {
        if (urlConnection != null) {
          urlConnection.disconnect();
        }
      }
    }
    throw e;
  }
}
